package sis.studentinfo;
import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;




public class StudentDirectoryTest {
	private StudentDirectory dir;
	
	@Before
	public void init(){
		dir = new StudentDirectory();
	}
	
	@Test
	public void testStoreAndRetrieve(){
		final int numberOfStudents = 10;
		
		for(int i=0; i<numberOfStudents;i++)
			addStudent(dir,i);
		
		for(int i=0; i<numberOfStudents; i++)
			verifyStudentLookup(dir,i);
	}
	
	void addStudent(StudentDirectory directory, int i){
		String id = "" + i;
		Student student = new Student(id);
		student.setId(id);
		student.addCredits(i);
		directory.add(student);
	}

	void verifyStudentLookup(StudentDirectory directory, int i){
		String id = "" + i;
		Student student = dir.findById(id);
		assertEquals(id, student.getLastName());
		assertEquals(id, student.getId());
		assertEquals(i, student.getCredits());
	}
}
